package com.LeeCode;

/**
 * 找出第 K 个字符 II
 */

public class Code3307 {
    public static void main(String[] args) {
        long k = 3;
        int[] operations = {1, 0};
        System.out.println(new Code3307().kthCharacter(k, operations));
    }

    public char kthCharacter(long k, int[] operations) {
        int inc = 0;
        for (int i = 63 - Long.numberOfLeadingZeros(k - 1); i >= 0; i--) {
            if (k > (1L << i)) { // k 在右半边
                inc += operations[i];
                k -= 1L << i;
            }
        }
        return (char) ('a' + inc % 26);
    }
}
